import re
from playwright.sync_api import Page, expect, sync_playwright

'''
官方实例
'''
def test_homepage():
    # 实例化playwright
    playwright = sync_playwright().start()
    # 打开chrome浏览器,headless默认是True,无头模式,这里设置为False方便查看效果
    browser = playwright.chromium.launch(headless=False,args=["--start-maximized"])
    # 打开content
    content = browser.new_context(no_viewport=True)
    # 设置默认等待时间
    content.set_default_timeout(60000)
    # 打开一个窗口页面
    page = content.new_page()
    page.goto("https://playwright.dev/")
    # Expect a title "to contain" a substring.
    expect(page).to_have_title(re.compile("Playwright"))
    # create a locator
    get_started = page.get_by_role("link", name="Get started")
    # Expect an attribute "to be strictly equal" to the value.
    expect(get_started).to_have_attribute("href", "/docs/intro")
    # Click the get started link.
    get_started.click()
    # Expects the URL to contain intro.
    expect(page).to_have_url(re.compile(".*intro"))


